package com.operation.controller;

import com.operation.entity.UserInfo;
import com.operation.service.UserService;
import org.jasig.cas.client.authentication.AttributePrincipal;
import org.jasig.cas.client.util.AssertionHolder;
import org.jasig.cas.client.validation.Assertion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Created by 123 on 2018/4/24.
 */

@Controller
public class TController {

    @Autowired
    UserService userService;

    @RequestMapping(value = "tiao1",produces = "text/html;charset=UTF-8")
    public String tiao() {
        String page = null;
        UserInfo userInfo = new UserInfo();
        Assertion assertion = AssertionHolder.getAssertion();
        AttributePrincipal ap = assertion.getPrincipal();
        if (userService.isExist(Long.valueOf(ap.getName())) == 1) {
            System.out.println("++++++++++++++++++++++++++++++用户不存在");
            /*userInfo.setUserAccount(Long.valueOf(ap.getName()));
            userService.add(userInfo);*/
        } else {
            userInfo.setUserAccount(Long.valueOf(ap.getName()));
            userInfo.setUserPassword("1");

            if (userService.isIt(userInfo) != null) {
                userService.updateIsOnline(userInfo);
            }
            System.out.println("++++++++++++++++++++++++++++++用户已存在");
        }
        return "createli";
    }

    @RequestMapping(value = "tiao2",produces = "text/html;charset=UTF-8")
    public String tiaoa(){

        return "faultli";
    }

    @RequestMapping(value ="yeji",produces = "text/html;charset=UTF-8")
    public String tiaob(){
        return "performancesli";
    }

    @RequestMapping(value = "guanli",produces ="text/html;charset=UTF-8" )
    public String tiaoc(){

        return "websiteli";
    }
}
